/*
 *  Library for GYSCADA
 *
 *      Copyright (c) 2014, 2015, 2016 GYEE. All rights reserved
 *      Author: wangbo
 */
#ifndef __LIBGYSCADA_H__
#define __LIBGYSCADA_H__

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

////////////////////////////////////////////////////////////////
/*
 * Miscellaneous APIs
 */
/*
 * libgyscada version
 * Return version of current library.
 * version include major version, minor version and revision
 * the three version encode into uint32_t type.
 * i.e. the version is 1.15.8 and the return value is 0x011508
 */
extern uint32_t libgyscada_version(void);

////////////////////////////////////////////////////////////////
typedef struct _libgyscada_t  libgyscada_t;

/*
 * Maximum range for timeouts t0 to t2: 1 s to 255 s, accuracy 1 s.
 */
typedef struct _libgyscada_config {
    uint8_t             t0;
    uint8_t             t1;
    uint8_t             t2;
} libgyscada_config_t;

////////////////////////////////////////////////////////////////
/*
 * Create GYSCADA
 */
extern libgyscada_t* libgyscada_create(const libgyscada_config_t* config);

/*
 * Destroy GYSCADA
 */
extern void libgyscada_destroy(libgyscada_t* gyscada);

////////////////////////////////////////////////////////////////
/*
 * Add Control client and its addrs
 */
/*
 * Add control client
 */
/*
 * Control Type
 */
typedef enum _libgyscada_control_type_t {
    CONTROL_TYPE_YX = 0,
    CONTROL_TYPE_YC,
    CONTROL_TYPE_YK,
    CONTROL_TYPE_YT,
    CONTROL_TYPE_YS
} libgyscada_control_type_t;
/*
 * Control Error Code
 */
typedef enum _libgyscada_control_error_t {
    CONTROL_SUCCESS = 0,
    CONTROL_ERROR_SEND,
    CONTROL_ERROR_INVALID_ADDRESS,
    CONTROL_ERROR_EXCEPTION,
    CONTROL_ERROR_INVALID_FUNCTION_CODE,
} libgyscada_control_error_t;

typedef void (*libgyscada_control_receive_t)(
    libgyscada_control_type_t* types, uint32_t* addrs,
    libgyscada_control_error_t* errors, uint32_t length, void* arg);

extern int libgyscada_control_add_client(
    libgyscada_t* gyscada, char* ip, int port,
    libgyscada_control_receive_t receive, void* arg,
    uint32_t* addrs, size_t size);
/*
 * Do control
 */
extern int libgyscada_control(
    libgyscada_t* gyscada, libgyscada_control_type_t* types, uint32_t* addrs,
    void** values, libgyscada_control_error_t* errors, uint32_t length);

#ifdef __cplusplus
}
#endif

#endif /* __LIBGYSCADA_H__ */
